/**
 * Created by WYH on 17/4/20.
 */
angular.module('tribalc').service(
    'RentProtocolModel',
    ['Enum','$rootScope','Api', function (TimeFormat,Enum,$rootScope,Api) {
        var RentProtocol = function (object) {
            var self = this;

            init();

            function init() {
                self.rentSex =object ? object.rentSex : null;
                self.rentIdNo =object ? object.rentIdNo : null;
                self.rentPhone =object ? object.rentPhone : null;
                self.rentJob =object ? object.rentJob : null;
                self.beginTime =object ? object.beginTime : null;
                self.payCycle =object ? object.payCycle : null;
                self.monthlyRent =object ? object.monthlyRent : null;
                self.communityId =object ? object.communityId : null;
                self.endTime =object ? object.endTime : null;
                self.pictures =object ? object.pictures : null;
                self.rentName = object ? object .rentName:null;
                self.deposit = object ? object .deposit:null;
                self.personNum=object ? object. personNum:null;
                self.type = object ? object. personNum:null;
                self.sourceId = object ? object. sourceId:null;
            }
        };


        RentProtocol.prototype.getCreateObject = function () {
            return {
                rentSex:this.rentSex,
                monthlyRent: Number(this.monthlyRent.toFixed(2)),
                payCycle: parseInt(this.payCycle),
                beginTime: Date.parse(this.beginTime),
                endTime: Date.parse(this.endTime),
                rentName:this.rentName,
                rentJob:this.rentJob,
                rentPhone:this.rentPhone,
                rentIdNo:this.rentIdNo,
                pictures: this.pictures,
                deposit:Number(this.deposit.toFixed(2)),
                personNum:this.personNum,
                communityId:this.communityId,
                sourceId:this.sourceId,
                type: this.type

            };

        };


        // function getReallyPicturePaths(pictures) {
        //     if (!pictures) return [];
        //     Array.from(pictures).forEach(function (path, index) {
        //         pictures[index] = RentProtocol.formatReallyPicturePath(path);
        //     });
        //     return pictures;
        // }
        //
        // function getOssPicturePaths(pictures) {
        //     if (!pictures) return [];
        //     Array.from(pictures).forEach(function (path, index) {
        //         pictures[index] = RentProtocol.formatOssPicturePath(path);
        //     });
        //     return pictures;
        // }
        //
        //
        //
        // RentProtocol.formatOssPicturePath = function (path) {
        //     if (path && path.indexOf(Api.ALIYUN_URL) !== -1) {
        //         path = 'oss://' + path.split(Api.ALIYUN_URL)[1];
        //     }
        //     return path;
        // };
        //
        // RentProtocol.formatReallyPicturePath = function (path) {
        //     var oss = 'oss://';
        //     if (path && path.indexOf(oss) !== -1) {
        //         path = Api.ALIYUN_URL + path.split(oss)[1];
        //     }
        //     return path;
        // };




        RentProtocol.setupRentProtocolList = function (array) {
            var rentList = [];
            array.forEach(function (value) {
                var rent = new RentProtocol(value);
                rentList.push(rent);
            });
            return rentList;
        };

        return RentProtocol;


    }]
);